<template>
  <div class="newsPage">
    <div class="header">
      <div class="title">
        <span class="icon sz_newspaperF"> </span>
        <span class="txt">新闻资讯</span>
      </div>
      <div class="navList">
        <span
          :class="currentNav == index ? 'active' : ''"
          @click="changeNav(index)"
          v-for="(item, index) in newsList"
          :key="item.blockName + index"
          >{{ item.blockName }}</span
        >
      </div>
      <span class="more" @click="moreNews(newsList[currentNav].newBoardUrl)"
        >更多 <i class="sz_arrows_right"></i
      ></span>
    </div>
    <div class="content">
      <div class="imgList" v-if="1==0">
        <div class="imgItem" v-for="(item, index) in imgList" :key="index">
          <img :src="item.url" alt="" />
        </div>
      </div>
      <div class="imgBox" v-show="newsList[currentNav].newsDataList.slice(0, 5).filter((item) => item.imgBase64Str).length > 0">
          <Carousel :imgList="newsList[currentNav].newsDataList.slice(0, 5).filter((item) => item.imgBase64Str)"></Carousel>
        </div>
      <div class="newsList" :class="newsList[currentNav].newsDataList.slice(0, 5).filter((item) => item.imgBase64Str).length > 0 ? 'newsList2' : ''">
        <div
          class="newsItem"
          @click="toNewsDetail(item)"
          v-for="(item, index) in newsList[currentNav].newsDataList.slice(0, 5)"
          :key="index"
        >
          <span class="title" :title="item.title">{{ item.title }}</span>
          <span class="time">{{ item.createDate }}</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Carousel from '../carousel/index.vue'
export default {
  components: {
    Carousel
  },
  data() {
    return {
      navList: [
        // {
        //   name: "深州要闻",
        // },
        // {
        //   name: "经济动态",
        // },
        // {
        //   name: "部门动态",
        // },
        // {
        //   name: "国务院要闻",
        // },
      ], //页签列表
      imgList: [
        {
          url: require("../../imgs/bg.png"), //图片地址
          link: "", //跳转地址
        },
        {
          url: require("../../imgs/bg.png"), //图片地址
          link: "", //跳转地址
        },
        {
          url: require("../../imgs/bg.png"), //图片地址
          link: "", //跳转地址
        },
        {
          url: require("../../imgs/bg.png"), //图片地址
          link: "", //跳转地址
        },
      ], //图片列表

      newsList: [
        // {
        //   des: "11111111111111111",
        //   link: "",
        //   date: "2022-12-12",
        // },
        // { des: "11111111111111111", link: "", date: "2022-12-12" },
        // { des: "11111111111111111", link: "", date: "2022-12-12" },
        // { des: "11111111111111111", link: "", date: "2022-12-12" },
        // { des: "11111111111111111", link: "", date: "2022-12-12" },
      ],
      moreLink: "", //更多跳转地址
      currentNav: 0, //当前页签
    };
  },
  created() {},
  mounted() {
    this.getNewsData();
    
  },
  methods: {
    // 获取新闻数据
    getNewsData() {
      this.axios({
        url: "/seeyon/rest/select/News",
        method: "post",
        headers: {
          "Content-Type": "application/json",
          "token":localStorage.getItem("restToken"),
        },
        data: {
          loginName: localStorage.getItem("loginName"),
          blockName: "会议新闻",
        },
      }).then((res) => {
        console.log("获取新闻数据", res);
        this.newsList = res.data.data;
      });
    },
    // 切换页签
    changeNav(index) {
      this.currentNav = index;
    },
    // 更多新闻
    moreNews(url) {
      // window.open("/seeyon" + url, "_blank");
      this.axios({
        url: `/seeyon/oasso.do?method=redirect&loginName=${localStorage.getItem("loginName")}&url=${encodeURIComponent("/seeyon" + url)}`,
        method: "get",
        headers: {
          "Content-Type": "application/json",
        },
        // data: {
        //   loginName: localStorage.getItem("loginName"),
        //   url: "/seeyon" + item.url,
        // },
      }).then((res) => {
        console.log("点击新闻数据", res);
        window.open(res.data, "_blank");
      });
    },
    // 点击新闻
    toNewsDetail(item) {
      this.axios({
        url: `/seeyon/oasso.do?method=redirect&loginName=${localStorage.getItem("loginName")}&url=${encodeURIComponent("/seeyon" + item.url)}`,
        method: "get",
        headers: {
          "Content-Type": "application/json",
        },
        // data: {
        //   loginName: localStorage.getItem("loginName"),
        //   url: "/seeyon" + item.url,
        // },
      }).then((res) => {
        console.log("点击新闻数据", res);
        window.open(res.data, "_blank");
      });
      
    },
  },
};
</script>
<style lang="less" scoped>
.newsPage {
  width: 100%;
  height: 100%;
  .header {
    height: 50px;
    display: flex;
    align-items: center;
    position: relative;
    .title {
      font-weight: 600;
      font-size: 20px;
      line-height: 50px;
      display: flex;
      justify-content: space-between;
      .icon {
        margin-right: 5px;
        line-height: 50px;
        color: #1371ff;
        font-size: 20px;
        margin-right: 10px;
      }
    }
    .navList {
      margin-left: 20px;
      display: flex;
      height: 30px;
      span {
        font-size: 14px;
        padding: 0 15px;
        background-color: aliceblue;
        margin: 0 5px;
        border-radius: 15px;
        line-height: 30px;
        cursor: pointer;
      }
      .active {
        background-color: #2c85fb;
        color: #fff;
      }
    }
    .more {
      position: absolute;
      right: 0px;
      cursor: pointer;
      color: #a6a9ad;
      font-size: 14px;
      i {
        font-size: 12px;
      }
    }
  }
  .content {
    height: calc(100% - 50px);
    position: relative;
    display: flex;
    .imgList {
      height: 100%;
      width: 300px;
      overflow: hidden;
      margin-right: 10px;
      border-radius: 10px;
      .imgItem {
        height: 100%;
        float: left;
        img {
          width: 100%;
        }
      }
    }
    .imgBox{
      padding: 12px 0;
      box-sizing: border-box;
      min-width: 240px;
      margin-right: 10px;
    }
    .newsList {
      flex: 1;
      flex-grow: 1;
      min-width: 0px;
      .newsItem {
        width: 100%;
        line-height: 42px;
        height: 42px;
        .title {
          color: #121213;
          flex: 1;
          display: inline-block;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          cursor: pointer;
          width: calc(100% - 120px);
        }
        .time {
          color: #c7ccd1;
          width: 120px;
          display: inline-block;
          text-align: right;
          cursor: pointer;
          vertical-align: top;
        }
      }
    }
    .newsList2 .newsItem .title{
      width: calc(100% - 120px) !important;
    }
  }
}
</style>